<template>
  <div>
    <div class="filter-container" style="margin-bottom: 10px">
      <el-button @click="add" type="primary" icon="el-icon-plus">添加</el-button>
    </div>
    <el-table :data="list" 
      style="width: 99%" 
      border="true"
      stripe="true" 
      :header-cell-style="{background:'#eef1f6',color:'#606266'}" 
      max-height="800px">
      <el-table-column align="center" label="序号" width="50">
        <template slot-scope="scope">
          {{scope.$index+1}}
        </template>
      </el-table-column>
      <el-table-column align="center" prop="name" label="分类名称"></el-table-column>
      <el-table-column align="center" prop="intro" label="简介"></el-table-column>
       <el-table-column align="center" prop="order" label="排序"></el-table-column>
      <el-table-column align="center" label="操作" width="200">
        <template slot-scope="scope">
          <el-button type="primary" @click="edit(scope.$index, scope.row)" size="small" icon="el-icon-edit">编辑</el-button>
          <el-button type="danger" @click="del(scope.$index, scope.row)" size="small" icon="el-icon-delete">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <addclass ref="add" @then="cll"></addclass>
    <updataclass ref="updata" @then="cll"></updataclass>
  </div>
</template>

<script>
  import {
    doctortype,
    deletetype
  } from "@/api/user/user"
  import addclass from "@/components/doctor/adddoctype.vue"
  import updataclass from "@/components/doctor/updatadoctype.vue"
  export default {
    components: {
      addclass,
      updataclass
    },
    data() {
      return {
        list: [],
      }
    },
    created() {
      this.getdoctype()
    },
    methods: {
      del(index, row) {
        let that = this;
        this.$confirm('此操作将永久删除该分类, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          deletetype({
            field: "type_id",
            op: "=",
            value: row.type_id
          }).then(() => {
            that.$message({
              type: 'success',
              message: '删除成功!'
            });
            that.getdoctype()
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
      },
      edit(index, row) {
        this.$refs.updata.add(row)
      },
      cll() {
        this.$message({
          type: "success",
          message: "添加成功!",
        });
        this.getdoctype()
      },
      add() {
        this.$refs.add.add()
      },
      getdoctype() {
        let that = this;
        doctortype({
          field: "type_id",
          op: ">",
          value: "0"
        }).then(res => {
          console.log(res)
          that.list = res
        })
      }
    }
  }
</script>
